<?php session_start();  ?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <?php  
          $con= mysql_connect("localhost","root","");
        if(!$con){
die('Connection Error!:' . mysql_error());
}
mysql_select_db ("usabilityevaluation",$con);

//save task and retrive its ID;

$title=$_POST['tasktitle'];
$time=$_POST['duration'];
$comment=$_POST["taskComment"];

//$_SESSION['id_task']=0;
//$task_id=$_SESSION['id_task'];
$exp_id=$_SESSION['id_Exp'];
$task_id;
$result = mysql_query("SELECT MAX(id_task) FROM task WHERE id_experiment='$exp_id'") ;
$num_results = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
if ($num_results ==0){$task_id=1;}
else {$task_id=$row[0] + 1;}
}

$query3="INSERT INTO task (Title,Duration,Comment,id_experiment,id_task) 
        VALUES ('$title ','$time','$comment',$exp_id,$task_id)";
echo "<script>alert('this is task insert')</script>";
@mysql_query($query3) or die('Error, insert query failed');
$_SESSION['id_task']=$task_id;
//=$_SESSION['id_task'];
         mysql_close($con);
        header("Location: questionSave.php"); 
        ?>
        
    </body>
</html>
